package org.ch02.test05;

import org.ch02.entity.Student;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;

/**
 * 其它 API
 *
 * @author ZQX
 * @date 2025-03-18
 */
public class MainTest02 {
    public static void main(String[] args) throws Exception {
        Class<?> clazz = Student.class;

        Field nameFiled = clazz.getDeclaredField("name");

        // 坑：这里获取的是字段类型的访问修饰符 - String.class
        Class<?> typeClass = nameFiled.getType();
        int fieldTypeModifiers = typeClass.getModifiers();

        // 正解：我们要获取的是字段的访问修饰符 - private
        int fieldModifiers = nameFiled.getModifiers();

        boolean bl1 = Modifier.isPublic(fieldTypeModifiers);
        boolean bl2 = Modifier.isPrivate(fieldModifiers);

        System.out.println(bl1);
        System.out.println(bl2);
    }
}
